package cn.itcast.jdbc;

import cn.itcast.util.JDBCUtil;

import java.sql.*;
import java.util.Scanner;

/*
数据获取
待解决问题，是否是最后一行
 */
public class JDBC_Demo7 {

    public static boolean login(String user,String password) throws SQLException {
        Connection conn = null;
        Statement statement = null;
        JDBCUtil jdbcUtil = new JDBCUtil();
        conn = JDBCUtil.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("select * from user where username = '" + user + "'and password = '"+ password+"'");
        return rs.next();

    }

    public static void main(String[] args) throws SQLException {
        Scanner cin = new Scanner(System.in);
        System.out.println("请输入姓名：");
        String user = cin.nextLine();
        System.out.println("请输入密码：");
        String password = cin.nextLine();
        if(login(user,password))
        {
            System.out.println("登录成功");
        }
        else System.out.println("登录失败");
    }


}
